Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous and certificate authentication #164

Merged

Conversation

ritzcrackr
Copy link
Contributor

Description

This Pull Request adds support for using certificate authentication and removes the need for credentials for Confluence Servers that do not require them. While this may look like a huge change, it does touch almost all the files, at its heart it is just enabling each function to pass a certificate instead of PSCredentials to Invoke-WebRequest. Invoke-WebRequest already supports certificate authentication.

I accomplished the certificate support by changing how the splatting from the outer functions to Invoke-Method and then to Invoke-WebRequest happened. Along the way I created a helper function called Copy-CommonParameter to assist in copying the appropriate $PSBoundParameters to enable better handling of parameters. I used Copy-CommonParameters anytime I needed to pass the auth parameters (i.e. $Credential or $Certificate) to an inner function call. By leveraging splatting I didn't need to know which parameter was set.

As I was updating the passing of parameters logic via splatting, I took the opportunity to simplify some logic. I didn't make any changes that added or removed features. I did take the time to fix the casing on ApiUri and [uri] to be consistent with the other parameters.

I believe the code is actually easier to read and understand after this PR as its flow is much more straightforward.

Before submitting I ran all the included tests along with porting my some of my existing scripts to work with this module.

Motivation and Context

The motivation behind this commit is that I maintain my own private PowerShell Module/Scripts for Confluence. My work was more a thin wrapper on Invoke-RestMethod without many of niceties provided by this module or PowerShell Core 6 support. Though this module has one big limitation, I need to use certificate authentication with my instance of Confluence. So instead of trying to maintain my own private module/scripts I would like to contribute to an open source Confluence PowerShell Module. This commit would enable me to replace my existing work and be a starting point for future commits.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • I have added Pester Tests that describe what my changes should do.
  • I have updated the documentation accordingly.

Copy-CommonParameter.ps1
-This function simplifies the propagating of parameters for splatting.
-The default parameters are just the auth parameters

Invoke-Method.ps1
-Updated to support pass Certificate to Invoke-WebRequest.
-Rename $Uri to have a consistent case both inside and from callers.
-Leveraged Copy-CommonParameters to simplify the code
-Simplified the appending of the query parameter logic.
-Fixed passing 'Body' to in the paginated results code path.

Invoke-Method.md
-Update docs to include the new Certificate Parameter.
Get-Page.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Get-Page.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Get-ChildPage.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.
-Simplified the "Recurse" logic.
-Identified issue handling ConfluencePS.Page objects via pipeline.

Get-ChildPage.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory

Get-Page.md
-Fixed 'ApiUri' casing in documentation
Add-Attachment.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Add-Attachment.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Add-Label.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Add-Label.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
…rmat

ConvertTo-StorageFormat.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

ConvertTo-StorageFormat.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Get-Attachment.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Get-Attachment.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Get-AttachmentFile.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Get-AttachmentFile.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Get-Lebal.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Get-Label.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Get-Space.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Get-Space.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
New-Page.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

New-Page.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
New-Space.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

New-Space.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Remove-Attachment.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Remove-Attachment.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Remove-Label.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Remove-Label.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Remove-Page.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Remove-Page.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Remove-Space.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Remove-Space.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Set-Attachment.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Set-Attachment.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Set-Label.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Set-Label.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
Set-Page.ps1
-Added Certificate Parameter
-Made Credential Parameter not mandatory
-Rename $ApiUri to have proper casing.
-Simplified the propagating of the the splatted parameters.

Set-Page.md
-Added Certificate Parameter
-Made Credential Parameter not mandatory
@ritzcrackr ritzcrackr requested review from a team as code owners February 11, 2019 05:05
@ghost ghost added the Status:In Review label Feb 11, 2019
@ritzcrackr
Copy link
Contributor Author

@lipkau, Is there anything I can do to get this PR accepted? I would really like to use the official release of this module but my company's Atlassian setup requires Certificate Authentication.

@ghost ghost assigned lipkau Feb 21, 2019
Copy link
Member

@lipkau lipkau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!
thanks for that!

I might require your help to move this to the v3 branch, as I don't have a setup where I can test if this works.
Ar you on the slack server already?

ConfluencePS/Private/Copy-CommonParameter.ps1 Outdated Show resolved Hide resolved
ConfluencePS/Private/Copy-CommonParameter.ps1 Outdated Show resolved Hide resolved
ConfluencePS/Public/Get-ChildPage.ps1 Outdated Show resolved Hide resolved
ConfluencePS/Public/New-Page.ps1 Outdated Show resolved Hide resolved
@lipkau
Copy link
Member

lipkau commented Feb 21, 2019

btw... this will be a nightmare to marge into my v3 branch :-(

@ritzcrackr
Copy link
Contributor Author

I can definitely help with porting these changes to the v3 branch. I have looked a bit at the v3 branch and the feature/useAtlassianPSConfiguration in your repo but I am unsure which is the best starting point. Is your plan to merge the feature/useAtlassianPSConfiguration feature branch into the v3 or into develop? I think you are merging feature/useAtlassianPSConfiguration into v3, correct? Should I wait until you do that or just start with feature/useAtlassianPSConfiguration?

I was also interested in making these same changes to the JiraPS project. I wanted to get them accepted to the ConfluencePS project first before spending the time to make the same changes to the JiraPS project. Let me know the best way to proceed.

@lipkau
Copy link
Member

lipkau commented Feb 22, 2019

yes. feature/useAtlassianPSConfiguration is a feature branch for release/v3.0.
I am finishing up the update of already existing functions and will merge it.

My intention is to update AtlassianPSConfiguration to have a property for the certificate in the [AtlassianPS.ServerData] class and have it be populated for a specific server with Connect-ConfluenceServer.

@lipkau lipkau merged commit c7daf91 into AtlassianPS:develop Feb 22, 2019
@ghost ghost removed the Status:In Review label Feb 22, 2019
@ritzcrackr ritzcrackr deleted the AnonymousAndCertificateAuthentication branch February 23, 2019 14:44
@lipkau lipkau added this to the v2.5 milestone Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants